package com.beemans.topon.data

import androidx.annotation.Keep
import com.anythink.china.api.ChinaDeviceDataInfo
import com.anythink.core.api.ATSDK
import com.anythink.core.api.DeviceDataInfo
import com.anythink.network.baidu.BaiduATCustomController
import com.anythink.network.baidu.BaiduATInitManager
import com.anythink.network.gdt.GDTATCustomController
import com.anythink.network.gdt.GDTATInitManager
import com.anythink.network.toutiao.TTATInitManager
import com.bytedance.sdk.openadsdk.TTCustomController

/**
 * @author ti
 * @date 2022/8/30.
 */
@Keep
class PrivacyConfig {
    private var deviceInfoArr: Array<out String>? = null
    private var ttCustomController: TTCustomController? = null
    private var gdtCustomController: GDTATCustomController? = null
    private var bdCustomController: BaiduATCustomController? = null

    /**
     * TopOn 隐私数据上报配置
     */
    fun setDeniedDeviceInfo(vararg deviceInfo: String) {
        deviceInfoArr = deviceInfo
    }

    /**
     * 穿山甲 隐私数据上报配置
     */
    fun setTtCustomController(ttCustomController: TTCustomController) {
        this.ttCustomController = ttCustomController
    }

    /**
     * 优量汇 隐私数据上报配置
     */
    fun setGdtCustomController(gdtCustomController: GDTATCustomController) {
        this.gdtCustomController = gdtCustomController
    }

    /**
     * 百度 隐私数据上报配置
     */
    fun setBdCustomController(bdCustomController: BaiduATCustomController) {
        this.bdCustomController = bdCustomController
    }

    /**
     * 配置生效
     */
    internal fun configure() {
        //TopOn 隐私数据上报配置
        deviceInfoArr?.let { ATSDK.deniedUploadDeviceInfo(*it) }
        //穿山甲 隐私数据上报配置
        ttCustomController?.let { TTATInitManager.getInstance().setTtCustomController(it) }
        //优量汇 隐私数据上报配置
        gdtCustomController?.let { GDTATInitManager.getInstance().setGDTATCustomController(it) }
        //百度 隐私数据上报配置
        bdCustomController?.let { BaiduATInitManager.getInstance().setBaiduATCustomController(it) }
    }

    companion object {

        val defaultDeviceInfoArr by lazy {
            arrayOf(
                DeviceDataInfo.DEVICE_SCREEN_SIZE,  //屏幕分辨率
                DeviceDataInfo.ANDROID_ID,          //Android ID
                DeviceDataInfo.APP_PACKAGE_NAME,    //应用包名
                DeviceDataInfo.APP_VERSION_CODE,    //应用版本号
                DeviceDataInfo.APP_VERSION_NAME,    //应用版本名
                DeviceDataInfo.BRAND,               //手机品牌
                DeviceDataInfo.GAID,                //Google Ad ID
                DeviceDataInfo.LANGUAGE,            //语言
                DeviceDataInfo.MCC,                 //移动网络代码
                DeviceDataInfo.MNC,                 //移动国家代码
                DeviceDataInfo.MODEL,               //手机机型
                DeviceDataInfo.ORIENTATION,         //屏幕方向
                DeviceDataInfo.OS_VERSION_CODE,     //系统版本号
                DeviceDataInfo.OS_VERSION_NAME,     //系统版本名
                DeviceDataInfo.TIMEZONE,            //时区
                DeviceDataInfo.USER_AGENT,          //User Agent
                DeviceDataInfo.NETWORK_TYPE,        //网络类型
                DeviceDataInfo.INSTALLER,           //应用安装来源

                ChinaDeviceDataInfo.MAC,            //MAC地址
                ChinaDeviceDataInfo.IMEI,           //国际移动设备识别码
                ChinaDeviceDataInfo.OAID,           //OAID
                ChinaDeviceDataInfo.SSID,           //WIFI名称
            )
        }

        val defaultTtController by lazy {
            object : TTCustomController() {
                override fun isCanUseLocation() = false         //是否允许穿山甲SDK主动使用地理位置信息
                override fun alist() = false                    //是否允许穿山甲SDK主动获取设备上应用安装列表的采集权限
                override fun isCanUsePhoneState() = false       //是否允许穿山甲SDK主动使用手机硬件参数，如：imei
                override fun isCanUseWifiState() = false        //是否允许穿山甲SDK主动使用ACCESS_WIFI_STATE权限
                override fun isCanUseWriteExternal() = false    //是否允许穿山甲SDK主动使用存储权限
                override fun isCanUseAndroidId() = false        //是否允许穿山甲SDK主动使用AndroidId
            }
        }

        val defaultGdtController by lazy {
            object : GDTATCustomController() {
                override fun getAgreePrivacyStrategy() = false
            }
        }

        val defaultBdController by lazy {
            object : BaiduATCustomController() {
                override fun getPermissionReadDeviceID() = false    //允许百度SDK可以获取设备id，如imei
                override fun getPermissionLocation() = false        //允许百度SDK可以使用定位权限
                override fun getPermissionStorage() = false         //允许百度SDK可以使用存储空间
                override fun getPermissionAppList() = false         //允许百度SDK可以使用获取应用安装列表权限
                override fun getPermissionOAID() = false            //允许百度SDK可以使用OAID
                override fun getPermissionDeviceInfo() = false      //允许百度SDK可以使用设备信息
                override fun getPermissionAppUpdate() = false       //设置百度SDK是否允许获取APP更新权限
                override fun getPermissionRunningApp() = false      //设置百度SDK是否允许获取运行中的APP权限
            }
        }
    }
}